﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Daybreak.Core.Terrains
{
    public class SurfaceImage
    {
        #region Private Members

        string m_ImageFilePath;
        double m_North;
        double m_South;
        double m_West;
        double m_East;
        Texture2D m_Texture;
        bool m_Enabled = true;
        
        #endregion

        public DateTime LastUpdate = DateTime.Now;
        public byte Opacity = 255;

        public SurfaceImage(string imageFilePath, double north, double south,
            double west, double east, Texture2D texture)
        {
            m_ImageFilePath = imageFilePath;
            m_North = north;
            m_South = south;
            m_West = west;
            m_East = east;
            m_Texture = texture;
        }

        public void Dispose()
        {
            /*	if(m_Texture != null && !m_Texture.Disposed)
                {
                    m_Texture.Dispose();
                    m_Texture = null;
                }*/
        }

        public Vector2 GetTextureCoordinate(double latitude, double longitude)
        {
            double deltaLat = m_North - latitude;
            double deltaLon = longitude - m_West;

            double latRange = m_North - m_South;
            double lonRange = m_East - m_West;

            Vector2 v = new Vector2(
                (float)(deltaLat / latRange),
                (float)(deltaLon / lonRange));

            return v;
        }

        #region Properties

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="SurfaceImage"/> is enabled. Useful if you don't want the surface renderer 
        /// to render an image without removing the image from the renderer
        /// </summary>
        /// <value>
        /// 	<c>true</c> if enabled; otherwise, <c>false</c>.
        /// </value>
        public bool Enabled
        {
            get
            {
                return m_Enabled;
            }

            set
            {
                m_Enabled = value;
            }
        }
        public double North
        {
            get
            {
                return m_North;
            }
        }
        public double South
        {
            get
            {
                return m_South;
            }
        }
        public double West
        {
            get
            {
                return m_West;
            }
        }
        public double East
        {
            get
            {
                return m_East;
            }
        }

        public string ImageFilePath
        {
            get
            {
                return m_ImageFilePath;
            }
        }

        public Texture2D ImageTexture
        {
            get
            {
                return m_Texture;
            }
            set
            {
                m_Texture = value;
            }
        }
        #endregion


    }
}
